﻿<div>
    <input type="button" value="Add" id="btn_addPerson" />
    Name:<input type="text" id="txt_personName" />
    <input type="button" id="btn_searchPerson" value="Search" />

    <div id="person_list"></div>
    <div id="person_dialog">
        <table class="tab">
            <tr>
                <td>Id</td>
                <td>
                    <input type="text" id="txt_person_id" /></td>
            </tr>
            <tr>
                <td>Name</td>
                <td>
                    <input type="text" id="txt_person_name" /></td>
            </tr>
            <tr>
                <td>Birthday</td>
                <td>
                    <input type="text" id="txt_person_birthday" /></td>
            </tr>
            <tr>
                <td>Address</td>
                <td>
                    <input type="text" id="txt_person_address" /></td>
            </tr>
        </table>
    </div>
</div>
<script>
    initDialog("person_dialog", 360, 550, function () {
        var oldstate = _historyHelper.currentHistoryState;
        var p_id = $("#txt_person_id").val();
        var p_name = $("#txt_person_name").val();
        var p_birthday = $("#txt_person_birthday").val();
        var p_address = $("#txt_person_address").val();
        if (oldstate.action == "EditPerson" || oldstate.action == "AddPerson") {
            state = { ran: Math.random(), action: oldstate.action, id: p_id, name: p_name, birthday: p_birthday, address: p_address, ran: Math.random() };
        }
        _processPerson.doAction(state);
        _historyHelper.replaceLink({ action: "GetPersonList" }, _historyHelper.baseUrl + "?action=GetPersonList");
    }, function () {
        var oldstate = _historyHelper.currentHistoryState;
        _historyHelper.replaceLink(oldstate, _historyHelper.baseUrl + "?action=GetPersonList");
    });
    document.getElementById("btn_addPerson").addEventListener("click", function () {
        _controller.doAction({ action: 'AddPerson', mode: "dialog" });
    }, false);
</script>
